﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DbFrame.Test.Extend
{
    using DbFrame.Class;
    using Dapper;
    using System.Data;

    /// <summary>
    /// MySql 扩展
    /// </summary>
    public class SqlExtend
    {
        private IDbConnection _IDbConnection = null;
        public SqlExtend()
        {
            DBContext.Initialization("Server=.;Database=AppDB;User ID=sa;Password=123456;",
                    "SELECT SCOPE_IDENTITY();",
                    (ConnectionString) =>
                    {
                        _IDbConnection = new MySql.Data.MySqlClient.MySqlConnection(ConnectionString);
                        return _IDbConnection;
                    },
                    (SqlStr, Page, PageSize, Param) =>
                    {
                        var _Total = this._IDbConnection.QuerySingle<int>("Select Count(1) From (" + SqlStr + ") As t", Param);
                        int Num = (Page - 1) * PageSize;
                        SqlStr += " limit " + Num + "," + PageSize;
                        return new Paging()
                        {
                            Table = this._IDbConnection.ExecuteReader(SqlStr, Param).ToDataTable(),
                            Total = _Total
                        };
                    },
                    (TabName, FieldNum, Where, Param) =>
                    {
                        return @"SELECT IFNULL(MAX(CONVERT(INT," + FieldNum + ")),0) FROM " + TabName + " WHERE 1=1 " + Where;
                    });
        }
    }


    /// <summary>
    /// Oracle 扩展
    /// </summary>
    public class OracleExtend
    {
        IDbConnection _IDbConnection = null;
        public OracleExtend()
        {
            //同 mysql Extend 配置


        }
    }





}
